package com.pan.admin.module.loanProduct.entity;


import com.gitee.apanlh.util.valid.ValidParam;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description: 所有的字段以及字段值
 * @Author: ghb
 * @Date: 2023/9/26 15:02
 */

public class FieldAndFieldValueVo {
    private Integer loanFormFieldId;
    private String fieldName;
    private Integer loanFormFieldValueId;
    private String fieldValue;



    public List<ProductFieldVo> getList(List<FieldAndFieldValueVo> list){
        // 去除重复关联主键ID
        List<FieldAndFieldValueVo> distinctList = list.stream()
                .collect(Collectors.toMap(FieldAndFieldValueVo::getLoanFormFieldId, Function.identity(), (k, v) -> k))
                .values()
                .stream()
                .collect(Collectors.toList());
        List<ProductFieldVo> productFieldVoList = new ArrayList<>();

        if (!ValidParam.isEmpty(distinctList)) {
            for (FieldAndFieldValueVo obj: distinctList) {
                List<ProductFieldValueVo> productFieldValueVoList = new ArrayList<>();
                ProductFieldVo productFieldVo = new ProductFieldVo();
                if (!ValidParam.isEmpty(list)) {
                    for (FieldAndFieldValueVo fieldValueVo: list) {
                        if(obj.getLoanFormFieldId()==fieldValueVo.getLoanFormFieldId()){
                            ProductFieldValueVo productFieldValueVo = new ProductFieldValueVo();
                            productFieldValueVo.setFieldName(fieldValueVo.getFieldValue());
                            productFieldValueVo.setLoanFormFieldValueId(fieldValueVo.getLoanFormFieldValueId());
                            productFieldValueVo.setLoanFormFieldId(fieldValueVo.getLoanFormFieldId());
                            productFieldValueVoList.add(productFieldValueVo);
                        }
                    }
                }

                productFieldVo.setFieldName(obj.getFieldName());
                productFieldVo.setLoanFormFieldId(obj.getLoanFormFieldId());
                productFieldVo.setProductFieldVoList(productFieldValueVoList);
                productFieldVoList.add(productFieldVo);
            }
        }

        return productFieldVoList;
    }
    public Integer getLoanFormFieldId() {
        return loanFormFieldId;
    }

    public void setLoanFormFieldId(Integer loanFormFieldId) {
        this.loanFormFieldId = loanFormFieldId;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public Integer getLoanFormFieldValueId() {
        return loanFormFieldValueId;
    }

    public void setLoanFormFieldValueId(Integer loanFormFieldValueId) {
        this.loanFormFieldValueId = loanFormFieldValueId;
    }

    public String getFieldValue() {
        return fieldValue;
    }

    public void setFieldValue(String fieldValue) {
        this.fieldValue = fieldValue;
    }
}
